import axios from "axios";
import config from "@/config/config.js";
import menuRequest from "@/api/menu.js";

const ledgerRequest={
    loadLedger(ledger,page=1,limit=10,callBack){
        let url = config.typeBaseUrl+"/ledger/list?page="+page+"&limit="+limit;
        if (ledger){
            if (ledger.machineCode){
                url += "&machineCode=" +ledger.machineCode;
            }
            if (ledger.machineName){
                url += "&machineName=" +ledger.machineName;
            }
            axios.get(url).then(res=>{
                callBack(res.data);
            })
        }
    },

    exportLedger(ledger,page=1,limit=10){
        let url = config.typeBaseUrl + "/ledger/export?page="+page+"&limit="+limit;
        if (ledger) {
            if (ledger.machineCode) {
                url += "&machineCode=" + ledger.machineCode;
            }
            if (ledger.machineName) {
                url += "&machineName=" + ledger.machineName;
            }
        }
        location.href = url;
    },

    addLedger(ledger,callBack){
        console.log(ledger)
        let url =config.typeBaseUrl +"/ledger/add";
        axios.put(url,ledger).then(res=>{
            callBack(res.data);
        })
    },

    updateLedger(ledger,callBack){
        let url = config.typeBaseUrl +"/ledger/updateLedger"
        axios.put(url,ledger).then(res=>{
            callBack(res.data);
        })
    },

    selectById(machineId,callBack){
        let url = config.typeBaseUrl +"/ledger/selectById?machineId=" +machineId;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    deleteLedger(machineId,callBack){
        let url = config.typeBaseUrl + "/ledger/updateLedgerStatus?machineId=" +machineId;
        axios.put(url).then(res=>{
            callBack(res.data);
        })
    },

    selectByDelete(callBack){
        let url = config.typeBaseUrl + "/ledger/delete?status="+99;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    updateByDelete(machineId,callBack){
        let url = config.typeBaseUrl +"/ledger/updateDeleteStatus?machineId="+machineId;
        axios.put(url).then(res=>{
            callBack(res.data);
        })
    },

    selectByCode(machineCode,callBack){
        let url = config.typeBaseUrl+"/ledger/selectByCode?machineCode="+machineCode;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    },

    selectByWorkShop(callBack){
        let url = config.typeBaseUrl+"/ledger/selectworkShop?workShopId="+1;
        axios.get(url).then(res=>{
            callBack(res.data);
        })
    }

}
export default ledgerRequest;